import {Component} from '@angular/core';
import {Router, NavigationEnd, ActivatedRoute, RoutesRecognized} from '@angular/router';
import {HttpService} from './http.service'
import {UserService} from './user.service'
import 'rxjs/add/operator/filter';
import * as ons from  'onsenui';


@Component({selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})
export class AppComponent {
  title = 'app';
  footerShow = false;
  routeData;
  // 监听路由变化部分
  constructor(
    private router : Router,
    private activeRoute : ActivatedRoute,
    private http : HttpService,
    private user : UserService,
  ) {
    // this.router.events.filter(e => e instanceof NavigationEnd)   .subscribe(e
    // => console.log('Route changed to: ' + e.url);
    ons.platform.select('ios')
    this.user.getUserInfo();
  }
  // 获取路由的附加data信息
  public ngOnInit() {
    this.routeData = this
      .router
      .events
      .subscribe((data) => {
        if (data instanceof RoutesRecognized) {
          this.footerShow = data.state.root.firstChild.data.footerShow;
          document.title = data.state.root.firstChild.data.title;
        }
      });
  }

  get isLoading() {
    return this.http.isLoading;
  }
}
